home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / JFC.bin / LineBorder.java < prev    next >
Text File  |  1998-06-30  |  5KB  |  153 lines

  1. /*
  2.  * @(#)LineBorder.java    1.11 98/02/02
  3.  *
  4.  * Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
  5.  *
  6.  * This software is the confidential and proprietary information of Sun
  7.  * Microsystems, Inc. ("Confidential Information").  You shall not
  8.  * disclose such Confidential Information and shall use it only in
  9.  * accordance with the terms of the license agreement you entered into
  10.  * with Sun.
  11.  *
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
  13.  * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  14.  * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  15.  * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
  16.  * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
  17.  * THIS SOFTWARE OR ITS DERIVATIVES.
  18.  *
  19.  */
  20. package com.sun.java.swing.border;
  21.  
  22. import java.awt.Graphics;
  23. import java.awt.Insets;
  24. import java.awt.Rectangle;
  25. import java.awt.Color;
  26. import java.awt.Component;
  27.  
  28. /**
  29.  * A class which implements a line border of arbitrary thickness
  30.  * and of a single color.
  31.  * <p>
  32.  * Warning: serialized objects of this class will not be compatible with
  33.  * future swing releases.  The current serialization support is appropriate
  34.  * for short term storage or RMI between Swing1.0 applications.  It will
  35.  * not be possible to load serialized Swing1.0 objects with future releases
  36.  * of Swing.  The JDK1.2 release of Swing will be the compatibility
  37.  * baseline for the serialized form of Swing objects.
  38.  *
  39.  * @version 1.11 02/02/98
  40.  * @author David Kloba
  41.  */
  42. public class LineBorder extends AbstractBorder
  43. {
  44.     private static Border blackLine;
  45.     private static Border grayLine;
  46.  
  47.     protected int thickness;
  48.     protected Color lineColor;
  49.     protected boolean roundedCorners;
  50.  
  51.     /** Convenience method for getting the Color.black LineBorder of thickness 1.
  52.       */
  53.     public static Border createBlackLineBorder() {
  54.         if (blackLine == null) {
  55.             blackLine = new LineBorder(Color.black, 1);
  56.         }
  57.         return blackLine;
  58.     }
  59.  
  60.     /** Convenience method for getting the Color.gray LineBorder of thickness 1.
  61.       */
  62.     public static Border createGrayLineBorder() {
  63.         if (grayLine == null) {
  64.             grayLine = new LineBorder(Color.gray, 1);
  65.         }
  66.         return grayLine;
  67.     }
  68.  
  69.     /** 
  70.      * Creates a line border with the specified color and a 
  71.      * thickness = 1.
  72.      * @param color the color for the border
  73.      */
  74.     public LineBorder(Color color) {
  75.         this(color, 1, false);
  76.     }
  77.  
  78.     /**
  79.      * Creates a line border with the specified color and thickness.
  80.      * @param color the color of the border
  81.      * @param thickness the thickness of the border
  82.      */
  83.     public LineBorder(Color color, int thickness)  {
  84.         this(color, thickness, false);
  85.     }
  86.  
  87.     /**
  88.      * Creates a line border with the specified color, thickness,
  89.      * and corner shape.
  90.      * @param color the color of the border
  91.      * @param thickness the thickness of the border
  92.      * @param roundedCorners whether or not border corners should be round
  93.      */
  94.     LineBorder(Color color, int thickness, boolean roundedCorners)  {
  95.         lineColor = color;
  96.         this.thickness = thickness;
  97.     this.roundedCorners = roundedCorners;
  98.     }
  99.  
  100.     /**
  101.      * Paints the border for the specified component with the 
  102.      * specified position and size.
  103.      * @param c the component for which this border is being painted
  104.      * @param g the paint graphics
  105.      * @param x the x position of the painted border
  106.      * @param y the y position of the painted border
  107.      * @param width the width of the painted border
  108.      * @param height the height of the painted border
  109.      */
  110.     public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
  111.         Color oldColor = g.getColor();
  112.         int i;
  113.  
  114.     /// PENDING(klobad) How/should do we support Roundtangles?
  115.         g.setColor(lineColor);
  116.         for(i = 0; i < thickness; i++)  {
  117.         if(!roundedCorners)
  118.                 g.drawRect(x+i, y+i, width-i-i-1, height-i-i-1);
  119.         else
  120.                 g.drawRoundRect(x+i, y+i, width-i-i-1, height-i-i-1, thickness, thickness);
  121.         }
  122.         g.setColor(oldColor);
  123.     }
  124.  
  125.     /**
  126.      * Returns the insets of the border.
  127.      * @param c the component for which this border insets value applies
  128.      */
  129.     public Insets getBorderInsets(Component c)       {
  130.         return new Insets(thickness, thickness, thickness, thickness);
  131.     }
  132.  
  133.     /**
  134.      * Returns the color of the border.
  135.      */
  136.     public Color getLineColor()     {
  137.         return lineColor;
  138.     }
  139.  
  140.     /**
  141.      * Returns the thickness of the border.
  142.      */
  143.     public int getThickness()       {
  144.         return thickness;
  145.     }
  146.  
  147.     /**
  148.      * Returns whether or not the border is opaque.
  149.      */
  150.     public boolean isBorderOpaque() { return true; }
  151.  
  152. }
  153.